#!/bin/bash
{
	#////////////////////////////////////
	# DietPi Cron.Hourly script
	#
	#////////////////////////////////////
	#
	# Info:
	# - Location: /etc/cron.hourly/dietpi
	#
	#////////////////////////////////////

	#----------------------------------------------------------------
	# Main Loop
	#----------------------------------------------------------------
	# Sync system time, if mode 3 (hourly) is detected
	grep -q '^[[:blank:]]*CONFIG_NTP_MODE=3' /boot/dietpi.txt && /boot/dietpi/func/run_ntpd 1
	#----------------------------------------------------------------
	# Clear /var/log files, if DietPi-RAMlog is detected
	[[ -f '/boot/dietpi/.installed' ]] && LOGGING_MODE=$(sed -n '/^[[:blank:]]*INDEX_LOGGING_CURRENT=/{s/^[^=]*=//p;q}' /boot/dietpi/.installed)
	# - Mode -1: Clear only
	if (( ${LOGGING_MODE:=0} == -1 )); then

		/boot/dietpi/func/dietpi-logclear 1

	# - Mode -2: Append logs to /root/logfile_storage/*, then clear
	elif (( $LOGGING_MODE == -2 )); then

		/boot/dietpi/func/dietpi-logclear 0

	fi
	#----------------------------------------------------------------
	exit
	#----------------------------------------------------------------
} > /dev/null
